﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WeekPicker : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void GenerateSeasonsandWeeks(Week selectedWeek)
    {
        List<Season> seasons = DataBase.Seasons.GetSeasons();

        foreach (var s in seasons)
        {
            ddSeason.Items.Add(new ListItem(s.StartYear.ToString(), s.ID.ToString()));
        }

        ddSeason.SelectedValue = selectedWeek.WeekSeason.ID.ToString();

        int weekCount = DataBase.Weeks.GetSeasonsWeekCount(selectedWeek.WeekSeason);

        for (int i = 1; i <= weekCount; i++ )
        {
            ddWeek.Items.Add(i.ToString());
        }

        ddWeek.SelectedValue = selectedWeek.Number.ToString();

    }
    protected void ddWeek_SelectedIndexChanged(object sender, EventArgs e)
    {
        RedirectToWeek();
    }
    protected void ddSeason_SelectedIndexChanged(object sender, EventArgs e)
    {
        RedirectToWeek();
    }

    private void RedirectToWeek()
    {
        var weekNumber = ddWeek.SelectedValue;
        var seasonID = ddSeason.SelectedValue;

        Response.Redirect(string.Format("DisplayWeek.aspx?Season={0}&Week={1}", seasonID, weekNumber));
    }
}